﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;

namespace LastfmTopDownloader
{
    public static class SongsTopListGetter
    {
        private static XmlDocument Requsest(string artist, uint limit)
        {
            var url = string.Format("http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist={0}&limit={1}&api_key={2}", artist, limit, Settings1.Default.LfmApiKey);
            var ret = new XmlDocument();
            ret.Load(url);
            return ret;
        }

        public static List<string> GetTop(string artist, uint limit)
        {
            var doc = Requsest(artist, limit);

            var nodeList = doc.SelectNodes("lfm/toptracks/track/name");
            if (nodeList == null) throw new ArgumentNullException("artist");

            return (from XmlNode node in nodeList select node.FirstChild.Value).ToList();
        }
    }
}
